package main

import "fmt"

//声明person类型
type person2 struct {
	name string
	age  int
}

//比较两个人的年龄，返回年龄大的那个人，并且返回年龄差
func Older(p1, p2 person2) (person2, int) {
	if p1.age > p2.age {
		return p1, p1.age - p2.age
	}
	return p2, p2.age - p1.age
}

func main() {
	var tom person2
	//通过赋值初始化
	tom.name, tom.age = "Tom", 18

	//字典形式初始化
	bob := person2{age: 25, name: "Bob"}

	//按照struct定义顺序初始化值
	paul := person2{"Paul", 43}

	tb_Older, tb_diff := Older(tom, bob)
	tp_Older, tp_diff := Older(tom, paul)
	bp_Older, bp_diff := Older(bob, paul)

	fmt.Printf("Of %s and %s, %s is older by %d years\n",
		tom.name, bob.name, tb_Older.name, tb_diff)
	fmt.Printf("Of %s and %s, %s is older by %d years\n",
		tom.name, paul.name, tp_Older.name, tp_diff)
	fmt.Printf("Of %s and %s, %s is older by %d years\n",
		bob.name, paul.name, bp_Older.name, bp_diff)

}
